/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "EInfo.h"

#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <QtCore/QFile>

#include "OutputParser.h"

using namespace Bio;

const QString	c_einfoUrl = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/einfo.fcgi";

///////////////////////////////////////////////////////////////////////////////
//	EInfo
///////////////////////////////////////////////////////////////////////////////

/**
	@class EInfo
	@brief Implementation of the Entrez 'EInfo' function.

	Provides an interface to the NCBI Entrez 'EInfo' function.

	See http://www.ncbi.nlm.nih.gov/books/NBK25499/ for details on
	the Entrez EInfo utility.
**/

/**
	Default Constructor. Creates a new EInfo operation.
**/
EInfo::EInfo()
{
}

/**
**/
EInfo::EInfo( const QString &db ) : m_db( db )
{
}

/**
**/
EInfo::~EInfo()
{
}

/**
**/
bool EInfo::exec()
{
	QUrl			url( c_einfoUrl );
	QUrlQuery		urlQuery;
	QFile			output( "ESpell.txt" );
	OutputParser	parser( output );

	if( !m_db.isEmpty() )
		urlQuery.addQueryItem( "db", m_db );

	url.setQuery( urlQuery );

	return execGet( url, parser );
}

/**
**/
void EInfo::setDatabase( const QString &db )
{
	m_db = db;
}

/**
**/
QString EInfo::getDatabase() const
{
	return m_db;
}
